#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 1e5 + 10;
priority_queue<int, vector<int>, greater<int>>pq;
int k, n;
void solve(){
	cin>>k>>n;
	for(int i=1;i<=k;i++){
		int v;
		cin>>v;
		pq.push(v);
	}
	
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x>pq.top()){
			pq.pop();
			pq.push(x);
		} 
		cout<<pq.top()<<' ';
	}
}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
